package com.wxlgroup.springboot.controller;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wxlgroup.springboot.commons.Response;
import com.wxlgroup.springboot.dao.EchartDao;
import com.wxlgroup.springboot.entity.Files;
import com.wxlgroup.springboot.entity.User;
import com.wxlgroup.springboot.service.UserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.*;

/**
 * @auther:wxl
 * @Date:2022/5/26-05-26-23:02
 * @Description:com.wxlgroup.springboot.controller
 * @Version:1.0
 */
@RestController
@RequestMapping("/echart")
public class EchartController {

    @Resource
    private UserService userService;

    @Resource
    private EchartDao echartDao;

    @GetMapping("/example")//
    public Response example(){
        Map<String,Object> data = new HashMap<>();
        data.put("x", CollectionUtil.newArrayList("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", " Sun "));
        data.put("y",CollectionUtil.newArrayList(150, 230, 224, 218, 135, 147, 260));
        return new Response("200",data,"");
    }


    @GetMapping("/members")
    public Response amount(){
        Response response = userService.queryAll();
        List<User> users = (List<User>) response.getResponseData();
        if(users!=null){
            //创建一个集合用来存储用户得地址得个数
            Map<String,Object> address = new HashMap<>();
            Integer dongbei=0;
            Integer huabei=0;
            Integer huazhong=0;
            Integer huadong=0;
            Integer huanan=0;
            Integer xinan=0;
            Integer xibei=0;
            for (User user : users) {
                String address1 = user.getAddress();
                if("黑龙江".equals(address1)||"吉林".equals(address1)||"辽宁".equals(address1)||"内蒙古".equals(address1)){
                    dongbei++;
                }else if("北京".equals(address1)||"天津".equals(address1)||"山西".equals(address1)||"河北".equals(address1)){
                    huabei++;
                }else if("河南".equals(address1)||"湖北".equals(address1)||"湖南".equals(address1)){
                    huazhong++;
                }else if("上海".equals(address1)||"江苏".equals(address1)||"浙江".equals(address1)
                        ||"安徽".equals(address1)||"江西".equals(address1)||
                        "山东".equals(address1)||"福建".equals(address1)||"台湾".equals(address1)){
                    huadong++;
                }else if("广东".equals(address1)||"广西壮族".equals(address1)||
                        "海南".equals(address1)||"香港".equals(address1)||"澳门".equals(address1)){
                    huanan++;
                }else if("四川".equals(address1)||"贵州".equals(address1)||
                        "云南".equals(address1)||"西藏".equals(address1)||"广西壮族".equals(address1)){
                    xinan++;
                }else if("陕西".equals(address1)||"甘肃".equals(address1)||
                        "青海".equals(address1)||"宁夏".equals(address1)||"新疆".equals(address1)){
                    xibei++;
                }
        }
            address.put("东北",dongbei);
            address.put("华北",huabei);
            address.put("华中",huazhong);
            address.put("华东",huadong);
            address.put("华南",huanan);
            address.put("西南",xinan);
            address.put("西北",xibei);

            return new Response("200",address,"查询成功");
        }else {
            return new Response("400",null,"没有用户");
        }

    }


    @GetMapping("/fileType")
    public Response amountFileType(){
        QueryWrapper<Files> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("type");
        Integer jpegCount=0;
        Integer docCount=0;
        Integer pngCount=0;
        Integer psdCount=0;
        Integer txtCount=0;
        Integer mp4Count=0;
        Integer rarCount=0;
        Integer pdfCount=0;
        Integer webpCount=0;
        Integer pptxCount=0;
        Integer xlsCount=0;
        Integer xlsxCount=0;
        //创建一个存储类型的集合
        List<String> types = new ArrayList<>();
        List<Files> files = echartDao.selectList(queryWrapper);
        for (Files file : files) {
            types.add(file.getType());
        }
        if(types.size()!=0){
            for (String type : types) {
                if("jpeg".equals(type)){
                    jpegCount++;
                }else if("doc".equals(type)){
                    docCount++;
                }else if("psd".equals(type)){
                    psdCount++;
                }else if("png".equals(type)){
                    pngCount++;
                }else if("txt".equals(type)){
                    txtCount++;
                }else if("mp4".equals(type)){
                    mp4Count++;
                }else if("rar".equals(type)){
                    rarCount++;
                }else if("pdf".equals(type)){
                    pdfCount++;
                }else if("webp".equals(type)){
                    webpCount++;
                }else if("pptx".equals(type)){
                    pptxCount++;
                }else if("xls".equals(type)){
                    xlsCount++;
                }else if("xlsx".equals(type)){
                    xlsxCount++;
                }
            }
            Map<String,Object> typesCount = new HashMap<>();
            typesCount.put("jpeg",jpegCount);
            typesCount.put("doc",docCount);
            typesCount.put("png",pngCount);
            typesCount.put("txt",txtCount);
            typesCount.put("psd",psdCount);
            typesCount.put("mp4",mp4Count);
            typesCount.put("pdf",pdfCount);
            typesCount.put("rar",rarCount);
            typesCount.put("webp",webpCount);
            typesCount.put("pptx",pptxCount);
            typesCount.put("xls",xlsCount);
            typesCount.put("xlsx",xlsxCount);
            return new Response("200",typesCount,"分类成功");
        }else {
            return new Response("400",null,"无文件!");
        }


    }

}
